﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Motorway_Simulator.Simulator;
using Motorway_Simulator.FileIO;

namespace Motorway_Simulator.GUI.Simulator
{
    public partial class SimulationForm : Form
    {
        private SimulationController simulationController;
        /// <summary>
        /// Initializes a new instance of the <see cref="SimulationForm"/> class.
        /// </summary>
        /// <param name="simulationController">The simulation controller.</param>
        public SimulationForm(string fileName)
        {
            if (!LoadSimulation(fileName))
            {
                this.Dispose();
            }
        }

        private SimulationCanvas simCanvas;


        internal bool LoadSimulation(string fileName)
        {
            FileAccessor fileAccessor = new FileAccessor();
            SimObject simObject = (SimObject)fileAccessor.Load(fileName);
            if (simObject != null)
            {
                simulationController = new SimulationController(simObject);
            simCanvas = new SimulationCanvas(simulationController);
            // simCanvas
            // 
            this.simCanvas.Location = new System.Drawing.Point(0, 0);
            this.simCanvas.Name = "simCanvas";
            this.simCanvas.Size = new System.Drawing.Size(3000, 3000);
            this.simCanvas.TabIndex = 0;
            this.Controls.Add(this.simCanvas);
            InitializeComponent();
            return true;
            }
            else return false;
            
        }

        internal void Play()
        {
            simulationController.Start();
        }


        internal void Stop()
        {
            simulationController.Stop();
        }

        internal void Restart()
        {
            simulationController.RestartSimulation();
        }

        internal void Pause()
        {
            simulationController.Pause();
        }
    }
}
